<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>其它</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        .box {
            position: absolute;
            top: 50px;
            left: 50px;
            width: 150px;
            height: 150px;
            background-color: #f00;
            overflow: scroll;
        }

        .content {
            position: relative;
            top: 50px;
            left: 50px;
        }

        .inner {
            width: 400px;
            height: 400px;
        }
    </style>
</head>

<body>

    <div class="content">
        <div class="box">
            <div class="inner"></div>
        </div>
    </div>

    <script src="../lib/jquery/jquery.min.js"></script>
    <script type="text/javascript">
        var $box = $(".box");

        // $ele.width/height([设置的值]) 直接获取/设置元素的宽高，值为number，不带单位
        console.log("元素的宽", $box.width());
        console.log("元素的高", $box.height());

        $box.width(300);
        console.log("设置元素的宽", $box.width());

        // $ele.position() 读取元素的offsetTop/Left，不可设置
        console.log("jQ读取offsetTop/Left", $box.position());

        // $ele.offset([{top: xx, left: xx}])  读取或者设置元素与页面的距离
        console.log("元素与页面的距离", $box.offset()); // {top: 100, left: 100}

        $box.offset({
            top: 30,
            left: 30
        })
        console.log("元素与页面的距离", $box.offset()); // {top: 30, left: 30}

        // $ele.scrollTop/Left() 读取/设置元素卷入上左距离，可以运用于animate
        $(".inner").click(function () {
            console.log("元素卷入上距离", $box.scrollTop());
            // $box.scrollLeft(100);
            console.log("元素卷入左距离", $box.scrollLeft());
            
            // $ele.end()  在链式操作中将转移的jQ对象返回转移前的jQ对象
            $box.animate({
                scrollTop: 200
            }, 3000)
            .find(".inner")
            .end()
            .css({
                backgroundColor: "#00f"
            })
            .attr("title", "hello");


        })


    </script>
</body>

</html>